package org.example;

import com.sun.jna.platform.win32.WinDef;
import org.example.mouse.GHubController;
import org.example.mouse.MouseController;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.concurrent.CompletableFuture;

import static org.example.GlobalKeyListenerExample.dun;
import static org.example.GlobalKeyListenerExample.lastmove;

public class Pic implements Runnable {
    public static volatile long pervshot = 0L;
    public static volatile boolean tz = false;
    public static volatile long tztime = 40L;
    public static volatile boolean kq = false;
    public static volatile boolean begin = false;

    public static volatile boolean skip = false;

    public static long killTimes = 0;

    public static boolean penz = false;
    public static boolean bs = false;
    public static boolean shot = false;

    public BufferedImage bufferedImage;

    public Pic(BufferedImage bufferedImage) {
        this.bufferedImage = bufferedImage;
    }

    public static void main(String[] args) throws Exception {
        screen(new Robot());
//        screenda(new Robot());
    }

    public static void screenda(Robot robot) {
        try {
            //zhongxin  639   479
            Rectangle screenRect2 = new Rectangle(0, 0, 1280, 960); // 你可以根据需要设置屏幕尺寸

            // 捕获屏幕
//            BufferedImage screenImage = robot.createScreenCapture(screenRect2);
//            BufferedImage screenImage2 = robot.createScreenCapture(screenRect2);

//            juda(robot, screenImage);
            // 保存截图
//            Thread.sleep(3000);
//            ImageIO.write(screenImage, "png", new File("all.png"));
//            System.out.println("截图成功，all.png");
//            System.exit(1);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static void screen(Robot robot) {
        try {
            Thread.sleep(3000L);
//            Rectangle screenRect = new Rectangle(640, 480, 3, 3); // 你可以根据需要设置屏幕尺寸
            Rectangle screenRect2 = new Rectangle(600, 400, 83, 123); // 你可以根据需要设置屏幕尺寸

            // 捕获屏幕
            BufferedImage screenImage = robot.createScreenCapture(screenRect2);
//            BufferedImage screenImage2 = robot.createScreenCapture(screenRect2);
            ju(robot, screenImage);
            // 保存截图
            Thread.sleep(1000);
            ImageIO.write(screenImage, "png", new File("dongtai2_SAMPLE.png"));
            System.out.println("截图成功，红色 SAMPLE.png");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static void ju(Robot robot, BufferedImage screenImage) {
        // 保存截图
//        int rgb = screenImage.getRGB(40+0, 80+0);
        //dongtai
        int rgb = screenImage.getRGB(38, 79);
        int rgbzx = screenImage.getRGB(39, 79);

        //钱包
        int qianbao = screenImage.getRGB(40 + 1, 80 + 1);
        int qianbao2 = screenImage.getRGB(40 + 1, 80 - 2);
        int qianbao3 = screenImage.getRGB(40 - 2, 80 + 1);
        int qianbao4 = screenImage.getRGB(40 - 2, 80 - 2);

        int penzi = screenImage.getRGB(40, 80);

        int qb_red = (qianbao >> 16) & 0xFF; // 获取红色分量
        int qb_green = (qianbao >> 8) & 0xFF; // 获取绿色分量
        int qb_blue = qianbao & 0xFF; // 获取蓝色分量

        int red = (rgb >> 16) & 0xFF; // 获取红色分量
        int green = (rgb >> 8) & 0xFF; // 获取绿色分量
        int blue = rgb & 0xFF; // 获取蓝色分量

        int zxred = (rgbzx >> 16) & 0xFF; // 获取红色分量
        int zxgreen = (rgbzx >> 8) & 0xFF; // 获取绿色分量
        int zxblue = rgbzx & 0xFF; // 获取蓝色分量


        int red_p = (penzi >> 16) & 0xFF; // 获取红色分量
        int green_p = (penzi >> 8) & 0xFF; // 获取绿色分量
        int blue_p = penzi & 0xFF; // 获取蓝色分量

        boolean zuoshang = false;
        boolean youshang = false;
        boolean zuoxia = false;
        boolean youxia = false;

        boolean zx_green = false;
        boolean zx_red = false;
        boolean zx_blue = false;
        penz = false;

        if ((red == 255) &&
                (green == 0) &&
                blue == 0) {
            zx_red = true;
        } else if (((red == 0) &&
                (green == 255) &&
                blue == 255) || ((zxred == 0) &&
                (zxgreen == 255) &&
                zxblue == 255)) {
            zx_blue = true;
        } else if ((red == 0) &&
                (green == 255) &&
                blue == 0) {
            zx_green = true;
        }

        if ((red_p == 0) &&
                (green_p == 255) &&
                blue == 255) {
            penz = true;
        }

//        if(skip) return;
//        if(!(GlobalKeyListenerExample.fk[5] || GlobalKeyListenerExample.fk[6] || GlobalKeyListenerExample.lietou) && !penz) {

//        if(!zx_red || !zx_blue) return;
        if (!zx_blue &&
                !((GlobalKeyListenerExample.fk[5] || GlobalKeyListenerExample.fk[6] || GlobalKeyListenerExample.lietou || GlobalKeyListenerExample.sq))
                && !penz) {
            return;
        }

        boolean kj = false;
        boolean penzmatch = false;
        boolean nihong = false;

        int x = 0;
        int y = 0;
        boolean m = false;
        ArrayList<Point> points = new ArrayList<>();

        int minx = Integer.MAX_VALUE;
        int miny = Integer.MAX_VALUE;
        int killsize = 0;
        for (int i = 0; i < 83; i++) {
            for (int j = 0; j < 123; j++) {
                // 获取具体像素，并以object类型表示
                Object data = screenImage.getRaster().getDataElements(i, j, null);
                int r = screenImage.getColorModel().getRed(data);
                int g = screenImage.getColorModel().getGreen(data);
                int b = screenImage.getColorModel().getBlue(data);
                if (rgbmatch(r, g, b)) {
                    x = i;
                    y = j;
                    points.add(new Point(i, j));
                    m = true;
                }

                if (killrgbmatch(r, g, b)) {
                    killsize++;
                }

                if (rgbmatch(r, g, b) && i > 31 && i < 49 && j > 71 && j < 89) {
                    penzmatch = true;
                }

                if (rgbmatch(r, g, b) && i < 39 && j < 79) {
                    zuoshang = true;
                    minx = Math.abs(i - 39) < minx ? Math.abs(i - 39) : minx;
                    miny = Math.abs(j - 79) < miny ? Math.abs(j - 79) : miny;
                } else if (rgbmatch(r, g, b) && i > 39 && j < 79) {
                    youshang = true;
                    minx = Math.abs(i - 39) < minx ? Math.abs(i - 39) : minx;
                    miny = Math.abs(j - 79) < miny ? Math.abs(j - 79) : miny;
                } else if (rgbmatch(r, g, b) && i < 39 && j > 79) {
                    zuoxia = true;
                    minx = Math.abs(i - 39) < minx ? Math.abs(i - 39) : minx;
                    miny = Math.abs(j - 79) < miny ? Math.abs(j - 79) : miny;
                } else if (rgbmatch(r, g, b) && i > 39 && j > 79) {
                    youxia = true;
                    minx = Math.abs(i - 39) < minx ? Math.abs(i - 39) : minx;
                    miny = Math.abs(j - 79) < miny ? Math.abs(j - 79) : miny;
                }
            }
        }

        if(killsize > 400) killTimes = System.currentTimeMillis();
        int headabs = 99;
        int headabsy = 99;
        kq = false;
        kq = headabs < 2 && headabsy < 7;
//        if(!zx_red) {
//            Point point = GHubController.calculateBoundingBoxCenter(points);
//            headabs = Math.abs(point.x - 39);
//            headabsy = Math.abs(point.y - 79);
//
//            if(!(zuoshang && zuoxia && youshang && youxia) && point.x > 39) {
//                //todo
//                CompletableFuture.supplyAsync(() -> {
//                    try {
//                        if(tz) return null;
//                        tz = true;
//                        robot.keyPress(KeyEvent.VK_D);
//                        Thread.sleep(Utils.random(tztime));
//                        robot.keyRelease(KeyEvent.VK_D);
//                        tz = false;
//                    } catch (Exception e) {
//                        throw new RuntimeException(e);
//                    }
//                    return null;
//                });
//            }else if (!(zuoshang && zuoxia && youshang && youxia) && point.x < 39) {
//                CompletableFuture.supplyAsync(() -> {
//                    try {
//                        if(tz) return null;
//                        tz = true;
//                        robot.keyPress(KeyEvent.VK_A);
//                        Thread.sleep(Utils.random(tztime));
//                        robot.keyRelease(KeyEvent.VK_A);
//                        tz = false;
//                    } catch (Exception e) {
//                        throw new RuntimeException(e);
//                    }
//                    return null;
//                });
//            }
//        }


//        if(m && (System.currentTimeMillis() - lastmove >= 10) && !zx_green) {
//            Point point = GHubController.calculateBoundingBoxCenter(points);
//            x = point.x;
//            y = point.y;
//            GHubController.mouseXY(x-39, y-79);
//            lastmove = System.currentTimeMillis();
//            System.out.println("move");
//        } else if (m && (System.currentTimeMillis() - lastmove >= 15) && !zx_green) {
//            Point point = GHubController.calculateBoundingBoxCenter(points);
//            x = point.x;
//            y = point.y;
//            GHubController.mouseXY(x-39, y-79);
//            lastmove = System.currentTimeMillis();
//        }

        boolean canstop = false;
//        if(!((red == 0) &&
//                (green == 255) &&
//                blue == 0)) {
//            canstop = true;
//        }

        if ((zx_blue || zx_red) && ((rgbmatch(qb_red, qb_green, qb_blue)
//            || rgbmatch(redfen(qianbao2), greenfen(qianbao2), bluefen(qianbao2))
//                || rgbmatch(redfen(qianbao3), greenfen(qianbao3), bluefen(qianbao3))
//                || rgbmatch(redfen(qianbao4), greenfen(qianbao4), bluefen(qianbao4))
        ) || (zuoshang && zuoxia && youshang && youxia) || kq)) {
            if (!penz) {
                shot(robot, zx_blue, nihong);
            } else if (canstop) {
                stopAndShot(robot);
            }
        }


        if ((penz) && (zuoshang && zuoxia && youshang && youxia)) {
//            System.out.println("penzi shangxia");
            shot(robot, zx_blue, nihong);
        }

    }

    private static void stopAndShot(Robot robot) {
        try {
            robot.keyRelease(KeyEvent.VK_W);
            robot.keyRelease(KeyEvent.VK_A);
            robot.keyRelease(KeyEvent.VK_S);
            robot.keyRelease(KeyEvent.VK_D);
//            Thread.sleep(140);
//            robot.keyPress(KeyEvent.VK_6);
//            robot.keyRelease(KeyEvent.VK_6);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    private static int redfen(int rgb) {
        return (rgb >> 16) & 0xFF; // 获取红色分量


    }

    private static int bluefen(int rgb) {
        return (rgb >> 8) & 0xFF; // 获取绿色分量
    }

    private static int greenfen(int rgb) {
        return rgb & 0xFF; // 获取蓝色分量
    }

    public static boolean killrgbmatch(int r, int g, int b) {
        if (r > 250 && g > 250 && b > 250) {
            return true;
        }
        return false;
    }

    public static boolean rgbmatch(int r, int g, int b) {


        //qianbao
//        if((r > 250) && (b > 240) && (g < 160)) {
//            return true;
//        }

        //zise
//not use        if((r > 200) && (b > 200) && (g < 180)) {
//        if((r > 220) && (b > 220) && (g < 180)) {
//            return true;
//        }

        //huangse
//        if((r > 200) && (g > 200) && (b < 120)) return true;
//        if((r > 240) && (g > 240)  && (b < 120)) return true;

        //hongse
        if ((r > 200) && (g < 70) && (b < 70)) return true;


//
//        if((r > 180) && (b > 180) && (g < 180)) {
//            return true;
//        }

        //daju
        if ((r == 189 || r == 188) &&
                (b == 189 || b == 188) &&
                (g < 135)) {
            return true;
        }

        return false;
    }

    public static void yellow(Robot robot, int red, int green, int blue) {
        if ((red == 188 || red == 189) && (green == 188 || green == 189)) {
            //=6
            robot.keyPress(KeyEvent.VK_6);
            robot.keyRelease(KeyEvent.VK_6);
        }
    }

    public static void red(Robot robot, int red, int green, int blue) {
        if ((red == 188 || red == 189) && (green == 188 || green == 189)) {
            //=6
            robot.keyPress(KeyEvent.VK_6);
            robot.keyRelease(KeyEvent.VK_6);
        }
    }

    public static void screen2(Robot robot) {
        try {
            Rectangle screenRect = new Rectangle(600, 400, 83, 123); // 你可以根据需要设置屏幕尺寸
            // 捕获屏幕
            BufferedImage screenImage = robot.createScreenCapture(screenRect);
            // 保存截图
            int rgb = screenImage.getRGB(40 + 1, 80 + 1);
            int red = (rgb >> 16) & 0xFF; // 获取红色分量
            int green = (rgb >> 8) & 0xFF; // 获取绿色分量
            int blue = rgb & 0xFF; // 获取蓝色分量
            if (!(red == 188 || red == 189) && !(green == 188 || green == 189)) {
//                System.out.println("red1:"+red);
//                System.out.println("green1:"+green);
            }

            int rgb60 = screenImage.getRGB(39 + 0, 79 + 0);
            int red06 = (rgb60 >> 16) & 0xFF; // 获取红色分量
            int green06 = (rgb60 >> 8) & 0xFF; // 获取绿色分量
            int blue60 = rgb60 & 0xFF; // 获取蓝色分量

            System.out.println("red06:" + red06);
            System.out.println("green06:" + green06);
            System.out.println("blue60:" + blue60);
            System.out.println("");


//            System.out.println("red1:"+red);
//            System.out.println("green1:"+green);
//            System.out.println("blue1:"+blue);
//            System.out.println("");


        } catch (Exception e) {
            e.printStackTrace();
        }
    }


//    public static void juda(Robot robot, BufferedImage screenImage) {
//        // 保存截图
////        int rgb = screenImage.getRGB(40+0, 80+0);
//        int rgb = screenImage.getRGB(639, 479);
//        //钱包
//        int qianbao = screenImage.getRGB(40 + 1, 80 + 1);
//        int qianbao2 = screenImage.getRGB(40 + 1, 80 - 2);
//        int qianbao3 = screenImage.getRGB(40 - 2, 80 + 1);
//        int qianbao4 = screenImage.getRGB(40 - 2, 80 - 2);
//
//        int penzi = screenImage.getRGB(40, 61);
//
//        int qb_red = (qianbao >> 16) & 0xFF; // 获取红色分量
//        int qb_green = (qianbao >> 8) & 0xFF; // 获取绿色分量
//        int qb_blue = qianbao & 0xFF; // 获取蓝色分量
//
//        int red = (rgb >> 16) & 0xFF; // 获取红色分量
//        int green = (rgb >> 8) & 0xFF; // 获取绿色分量
//        int blue = rgb & 0xFF; // 获取蓝色分量
//
//
//        int red_p = (penzi >> 16) & 0xFF; // 获取红色分量
//        int green_p = (penzi >> 8) & 0xFF; // 获取绿色分量
//        int blue_p = penzi & 0xFF; // 获取蓝色分量
//
//
//        boolean zuoshang = false;
//        boolean youshang = false;
//        boolean zuoxia = false;
//        boolean youxia = false;
//        boolean kj = false;
//        boolean penzmatch = false;
//        boolean nihong = false;
//
//        penz = false;
//        int x = 0;
//        int y = 0;
//        boolean m = false;
//        ArrayList<Point> points = new ArrayList<>();
//
//        for (int i = 0; i < 1280; i++) {
//            for (int j = 0; j < 960; j++) {
//                // 获取具体像素，并以object类型表示
//                Object data = screenImage.getRaster().getDataElements(i, j, null);
//                int r = screenImage.getColorModel().getRed(data);
//                int g = screenImage.getColorModel().getGreen(data);
//                int b = screenImage.getColorModel().getBlue(data);
//                if (rgbmatch(r, g, b)) {
//                    x = i;
//                    y = j;
//                    points.add(new Point(i, j));
//                    m = true;
//                }
//                if ((r == 0) &&
//                        (g == 255) &&
//                        b == 0 && (j != 79 & j != 80)) {
//                    penz = true;
//                }
//
//                if (rgbmatch(r, g, b) && i > 31 && i < 49 && j > 71 && j < 89) {
//                    penzmatch = true;
//                }
//
//                if (rgbmatch(r, g, b) && i < 639 && j < 479) {
//                    zuoshang = true;
//                } else if (rgbmatch(r, g, b) && i > 639 && j < 479) {
//                    youshang = true;
//                } else if (rgbmatch(r, g, b) && i < 639 && j > 479) {
//                    zuoxia = true;
//                } else if (rgbmatch(r, g, b) && i > 639 && j > 479) {
//                    youxia = true;
//                }
//            }
//        }
//
//        if ((red == 255) &&
//                (green == 0) &&
//                blue == 0) {
//            kj = true;
//        } else if ((red == 255) &&
//                (green == 255) &&
//                blue == 255) {
//            kj = true;
//            nihong = true;
//        }
//
////        if(m && kj) {
////            WinDef.POINT mousePosition = GHubController.getMousePosition();
////            System.out.println("current x:" + mousePosition.x);
////            System.out.println("current y:" + mousePosition.y);
////
////
////
////            Point point = GHubController.findClosestToCenter(points);
////            x = point.x;
////            y = point.y;
////
////            System.out.println("target x:" + y);
////            System.out.println("target y:" + y);
////            moveTimes ++;
////        }
//
//        boolean canstop = false;
//        if (!((red == 0) &&
//                (green == 255) &&
//                blue == 0)) {
//            canstop = true;
//        }
//
//        if ((
//                rgbmatch(qb_red, qb_green, qb_blue) ||
//                        rgbmatch(redfen(qianbao2), greenfen(qianbao2), bluefen(qianbao2)) ||
//                        rgbmatch(redfen(qianbao3), greenfen(qianbao3), bluefen(qianbao3)) ||
//                        rgbmatch(redfen(qianbao4), greenfen(qianbao4), bluefen(qianbao4))
//        ) || (zuoshang && zuoxia && youshang && youxia)) {
//            if (kj) {
//                shot(robot, kj, nihong);
//            } else if (canstop) {
//                stopAndShot(robot);
//            }
//        }
//
//
//        if (GlobalKeyListenerExample.fk[4] && penzmatch) {
//            shot(robot, kj, nihong);
//        }
//
//    }

    @Override
    public void run() {
//        while (true) {
//            BufferedImage take = null;
//            try {
//                take = GlobalKeyListenerExample.queue.take();
//            } catch (InterruptedException e) {
//                throw new RuntimeException(e);
//            }
//            ju(GlobalKeyListenerExample.robot, take);
//        }
        ju(GlobalKeyListenerExample.robot, this.bufferedImage);
    }

    public synchronized static void shot(Robot robot, boolean blue, boolean nihong) {
        try {
            skip = true;
            long time = System.currentTimeMillis();
            long kaiqiangjiange = time - pervshot;
//            long sleeptime = 101;
            long sleeptime = 110;
            long jiange = 330;
            if (GlobalKeyListenerExample.lietou) {
                jiange = 300;
                sleeptime=300;
            } else if (GlobalKeyListenerExample.fk[5]) {
                sleeptime = 130;
                if (kaiqiangjiange < 1000) {
                    sleeptime = 260;
                    jiange = 50;
                }
                jiange = 300;
            }

            if ((kaiqiangjiange < jiange + sleeptime && !GlobalKeyListenerExample.fk[5]) || (GlobalKeyListenerExample.fk[5] && kaiqiangjiange < 180))
                return;
            if (penz || GlobalKeyListenerExample.sq) {
                robot.keyPress(KeyEvent.VK_6);
                robot.keyRelease(KeyEvent.VK_6);
            }else if(GlobalKeyListenerExample.lietou){
                if(GlobalKeyListenerExample.fk[3]) {
                    robot.keyPress(KeyEvent.VK_E);
                    robot.keyRelease(KeyEvent.VK_E);
                }
                robot.keyPress(KeyEvent.VK_6);
                robot.keyRelease(KeyEvent.VK_6);
                robot.keyPress(KeyEvent.VK_D);
                Thread.sleep(Utils.random(300));
                robot.keyRelease(KeyEvent.VK_D);
            } else if (GlobalKeyListenerExample.fk[1]) {
                pervshot = time;
                robot.keyPress(KeyEvent.VK_6);
                robot.keyRelease(KeyEvent.VK_6);

                robot.keyPress(KeyEvent.VK_D);
                Thread.sleep(Utils.random(400));
                robot.keyRelease(KeyEvent.VK_D);
            } else if (GlobalKeyListenerExample.fk[3] && (!penz || GlobalKeyListenerExample.lietou)) {
                pervshot = time;
                robot.keyPress(KeyEvent.VK_6);
                robot.keyRelease(KeyEvent.VK_6);
                int m = KeyEvent.VK_D;
                if (GlobalKeyListenerExample.moveA) {
                    m = KeyEvent.VK_A;
                }
                final int mcode = m;
                robot.keyPress(mcode);
                Thread.sleep(10);
                robot.keyPress(KeyEvent.VK_E);
                robot.keyRelease(KeyEvent.VK_E);
                robot.keyRelease(mcode);

                robot.keyPress(KeyEvent.VK_2);
                robot.keyRelease(KeyEvent.VK_2);
                Thread.sleep(10);
                robot.keyPress(KeyEvent.VK_EQUALS);
                robot.keyRelease(KeyEvent.VK_EQUALS);
                if (GlobalKeyListenerExample.lietou) return;
                Thread.sleep(10);
                CompletableFuture.supplyAsync(() -> {
                    try {
                        robot.keyPress(mcode);
                        Thread.sleep(350);
                        robot.keyRelease(mcode);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    return null;
                });

//                robot.keyPress(KeyEvent.VK_PAGE_UP);
//                robot.keyRelease(KeyEvent.VK_PAGE_UP);
            } else if (GlobalKeyListenerExample.fk[2] && (!penz || GlobalKeyListenerExample.lietou)) {
                pervshot = time;
                robot.keyPress(KeyEvent.VK_6);
                robot.keyRelease(KeyEvent.VK_6);
                int m = KeyEvent.VK_D;
                if (GlobalKeyListenerExample.moveA) {
                    m = KeyEvent.VK_A;
                }
                final int mcode = m;
                if (!GlobalKeyListenerExample.lietou) {
                    robot.keyPress(KeyEvent.VK_E);
                    robot.keyRelease(KeyEvent.VK_E);
                    robot.keyPress(KeyEvent.VK_1);
                    robot.keyRelease(KeyEvent.VK_1);
                    robot.keyPress(KeyEvent.VK_1);
                    robot.keyRelease(KeyEvent.VK_1);

                    Thread.sleep(Utils.random(140));

//                    robot.keyPress(mcode);
//                    robot.keyRelease(mcode);

                    Thread.sleep(Utils.random(60));
                    robot.keyPress(KeyEvent.VK_6);
                    robot.keyRelease(KeyEvent.VK_6);
                    Thread.sleep(Utils.random(100));
                    robot.keyPress(KeyEvent.VK_8);
                    robot.keyRelease(KeyEvent.VK_8);
                }
                pervshot = time;
            } else if (GlobalKeyListenerExample.fk[5] || GlobalKeyListenerExample.lietou) {
                pervshot = time;
                baishe(robot, sleeptime);
            } else if (GlobalKeyListenerExample.fk[6] && !penz) {
                robot.keyPress(KeyEvent.VK_6);
                robot.keyRelease(KeyEvent.VK_6);
                robot.keyPress(KeyEvent.VK_CONTROL);
                robot.keyPress(KeyEvent.VK_6);
                Thread.sleep(390);
                robot.keyRelease(KeyEvent.VK_6);
                robot.keyRelease(KeyEvent.VK_CONTROL);
                pervshot = time;
            } else if (GlobalKeyListenerExample.fk[10]) {
                robot.keyPress(KeyEvent.VK_6);
                robot.keyRelease(KeyEvent.VK_6);
                Thread.sleep(50);
                robot.keyPress(KeyEvent.VK_G);
                robot.keyRelease(KeyEvent.VK_G);
                pervshot = time;
            } else if (GlobalKeyListenerExample.fk[12]) {
                robot.keyPress(KeyEvent.VK_6);
                robot.keyRelease(KeyEvent.VK_6);
                Thread.sleep(50);
                robot.keyPress(KeyEvent.VK_Y);
                robot.keyRelease(KeyEvent.VK_Y);
                pervshot = time;
            } else {
                robot.keyPress(KeyEvent.VK_6);
                robot.keyRelease(KeyEvent.VK_6);
                pervshot = time;
            }
            skip = false;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void baishe(Robot robot, long sleep) {
        try {
            if (false) {
                robot.keyPress(KeyEvent.VK_CONTROL);
                robot.keyPress(KeyEvent.VK_6);
                Thread.sleep(Utils.random(360));
                robot.keyRelease(KeyEvent.VK_6);
                robot.keyRelease(KeyEvent.VK_CONTROL);
            } else {
//                robot.keyRelease(KeyEvent.VK_D);
                robot.keyPress(KeyEvent.VK_CONTROL);

                long ts = 10;
                if (bs) Thread.sleep(100);

                robot.keyPress(KeyEvent.VK_A);
                robot.keyPress(KeyEvent.VK_D);
                robot.keyPress(KeyEvent.VK_6);
                Thread.sleep(Utils.random(30));
                robot.keyRelease(KeyEvent.VK_CONTROL);
                robot.keyRelease(KeyEvent.VK_A);
                robot.keyRelease(KeyEvent.VK_D);
                //BEGIN
                CompletableFuture.supplyAsync(() -> {
                    try {
                        begin = true;
                        Thread.sleep(Utils.random(1500));
                        begin = false;
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                    return null;
                });

                Thread.sleep(Utils.random(150));
//                robot.keyPress(KeyEvent.VK_D);
                robot.keyRelease(KeyEvent.VK_6);
//                robot.keyRelease(KeyEvent.VK_D);

//                if (true) {
//                    robot.keyPress(KeyEvent.VK_D);
//                    Thread.sleep(Utils.random(200));
//                    robot.keyRelease(KeyEvent.VK_D);
//                    Thread.sleep(Utils.random(100));
//                    for (int i = 0; i < 6; i++) {
//                        if (System.currentTimeMillis() - killTimes < 1500) break;
//                        robot.keyPress(KeyEvent.VK_6);
//                        robot.keyRelease(KeyEvent.VK_6);
//                        Thread.sleep(Utils.random(180));
//                    }
//                }

//                robot.keyPress(KeyEvent.VK_A);
//                Thread.sleep(Utils.random(100));
//                robot.keyRelease(KeyEvent.VK_A);
//                Thread.sleep(Utils.random(100));
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    private static long[] mtime = new long[]{30, 110, 90};
}